home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / LAPBTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-15  |  2.3 KB  |  104 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "ax25.h"
  4. #include "timer.h"
  5. #include "lapb.h"
  6.  
  7. void lapbstate();
  8.  
  9. /* Called whenever timer T1 expires */
  10. void
  11. recover(axp)
  12. register struct ax25_cb *axp;
  13. {
  14.     axp->t1.start *= 2;    /* Back off retransmit timer */
  15.     axp->flags.retrans = 1;
  16.  
  17.     switch(axp->state){
  18.     case SETUP:
  19.         if(axp->n2 != 0 && axp->retries == axp->n2){
  20.             free_q(&axp->txq);
  21.             axp->reason = LB_TIMEOUT;
  22.             lapbstate(axp,DISCONNECTED);
  23.         } else {
  24.             axp->retries++;
  25.             sendctl(axp,COMMAND,SABM|PF);
  26.             start_timer(&axp->t1);
  27.         }
  28.         break;
  29.     case DISCPENDING:
  30.         if(axp->n2 != 0 && axp->retries == axp->n2){
  31.             axp->reason = LB_TIMEOUT;
  32.             lapbstate(axp,DISCONNECTED);
  33.         } else {
  34.             axp->retries++;
  35.             sendctl(axp,COMMAND,DISC|PF);
  36.             start_timer(&axp->t1);
  37.         }
  38.         break;
  39.     case CONNECTED:
  40.         axp->retries = 0;
  41.     case RECOVERY:    /* note fall-thru */
  42.         if(axp->n2 != 0 && axp->retries == axp->n2){
  43.             /* Give up */
  44.             sendctl(axp,RESPONSE,DM|PF);
  45.             free_q(&axp->txq);
  46.             axp->reason = LB_TIMEOUT;
  47.             lapbstate(axp,DISCONNECTED);
  48.         } else {
  49.             /* Transmit poll */
  50.             tx_enq(axp);
  51.             axp->retries++;
  52.             lapbstate(axp,RECOVERY);
  53.         }
  54.         break;
  55.     }
  56. }
  57.  
  58.  
  59. /* Send a poll (S-frame command with the poll bit set) */
  60. void
  61. pollthem(axp)
  62. register struct ax25_cb *axp;
  63. {
  64.     if(axp->proto == V1)
  65.         return;    /* Not supported in the old protocol */
  66.     switch(axp->state){
  67.     case CONNECTED:
  68.         axp->retries = 0;
  69.         tx_enq(axp);
  70.         lapbstate(axp,RECOVERY);
  71.         break;
  72.     }
  73. }
  74. /* Transmit query */
  75. tx_enq(axp)
  76. register struct ax25_cb *axp;
  77. {
  78.     char ctl;
  79.     struct mbuf *bp;
  80.  
  81.     /* I believe that retransmitting the oldest unacked
  82.      * I-frame tends to give better performance than polling,
  83.      * as long as the frame isn't too "large", because
  84.      * chances are that the I frame got lost anyway.
  85.      * This is an option in LAPB, but not in the official AX.25.
  86.      */
  87.     if(axp->txq != NULLBUF
  88.      && ( len_mbuf(axp->txq) < axp->pthresh
  89.         || axp->proto == V1 || !axp->flags.remotebusy)){
  90.         /* Retransmit oldest unacked I-frame */
  91.         dup_p(&bp,axp->txq,0,len_mbuf(axp->txq));
  92.         ctl = PF | I | ((axp->vs - axp->unack) & MMASK) << 1
  93.          | axp->vr << 5;
  94.         sendframe(axp,COMMAND,ctl,bp);
  95.     } else {
  96.         ctl = len_mbuf(axp->rxq) >= axp->window ? RNR|PF : RR|PF;    
  97.         sendctl(axp,COMMAND,ctl);
  98.     }
  99.     axp->response = 0;    
  100.     stop_timer(&axp->t3);
  101.     start_timer(&axp->t1);
  102. }
  103.  
  104.